/*
 * Created: Author: Aléx Carvalho / Date: Mar 28, 2015
 * 
 * Changed: $Author: ac280593@gmail.com $ / $Date: 2015-06-11 01:31:49 -0300 (Thu, 11 Jun 2015) $
 */
package com.cpm.view.zk.field;

import com.cpm.view.IconKit;
import com.cpm.view.zk.IconElement;
import com.cpm.view.Icon;
import org.zkoss.zk.ui.HtmlBasedComponent;
import org.zkoss.zul.Button;
import org.zkoss.zul.Div;
import org.zkoss.zul.Textbox;

public class SearchField extends AbstractInputField<String>{

    private final Textbox textbox = new Textbox();
    private final Button button = new Button();
    private final Div panel = new Div();
    
    public SearchField() {
        initComponents();
    }

    @Override
    public void setValue(String value) {
        textbox.setValue(value);
    }

    @Override
    public String getValue() {
        return textbox.getValue();
    }

    @Override
    public boolean isEnabled() {
        return !textbox.isDisabled();
    }

    @Override
    public void setEnabled(boolean enable) {
        textbox.setDisabled(!enable);
        button.setDisabled(!enable);
    }

    @Override
    public HtmlBasedComponent getElement() {
        return panel;
    }
    
    private void initComponents(){
        
        textbox.setHflex("true");
        button.setWidth("30px");
        
        IconElement element = new  IconElement( new Icon(IconKit.SEARCH));
        panel.appendChild(textbox);
        panel.appendChild(element.getElement());
//        panel.appendChild(button);
        
        
        textbox.setSclass("no-border-fildbox");
        
        button.setIconSclass(IconKit.SEARCH.getValue());
    }
}
